<template>
  <BasicTitle :class="prefixCls" v-if="getTitle" :help-message="helpMessage">
    {{ getTitle }}
  </BasicTitle>
</template>
<script lang="ts">
  import type { PropType } from 'vue';

  import { computed, defineComponent } from 'vue';

  import { isFunction } from '@eacloud/utils';

  import { BasicTitle } from '@/components/Basic/index';
  import { useDesign } from '@/hooks/web/useDesign';

  export default defineComponent({
    name: 'AdListTitle',
    components: { BasicTitle },
    props: {
      title: {
        type: [Function, String] as PropType<((data: any) => string) | string>,
        required: true,
      },
      getSelectRows: {
        type: Function as PropType<() => any[]>,
        default: undefined,
      },
      helpMessage: {
        type: [String, Array] as PropType<string | string[]>,
        required: true,
      },
    },
    setup(props) {
      const { prefixCls } = useDesign('basic-table-title');

      const getTitle = computed(() => {
        const { title, getSelectRows = () => {} } = props;
        let tit = title;

        if (isFunction(title)) {
          tit = title({
            selectRows: getSelectRows(),
          });
        }
        return tit;
      });

      return { getTitle, prefixCls };
    },
  });
</script>
<style lang="scss">
  $prefix-cls: #{$namespace}-basic-table-title;

  .#{$prefix-cls} {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
</style>
